/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import business.CarModelBusiness;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import model.CarModel;

/**
 *
 * @author Nhang Con
 */
@ManagedBean
@RequestScoped
public class ModelBean {

    public CarModel getModel() {
        return model;
    }
    private List<CarModel> lmodel;

    public List<CarModel> getLmodel() {
        return lmodel;
    }

    public void setLmodel(List<CarModel> lmodel) {
        this.lmodel = lmodel;
    }

    public void setModel(CarModel model) {
        this.model = model;
    }
    private CarModel model;

    /** Creates a new instance of ModelBean */
    public ModelBean() {
        model = new CarModel();
        lmodel = modelBusiness.getListModel();
    }
    private CarModelBusiness modelBusiness = new CarModelBusiness();

    public String actionCreateModel() {
        if (modelBusiness.newCarModel(model)) {
             lmodel = modelBusiness.getListModel();
            return "managementcarmodel.xhtml";
        }
        return "error.xhtml";
    }

    public String actionUpdateModel(CarModel model) {

        if (modelBusiness.updateCarModel(model)) {
            return "managementcarmodel.xhtml";

        }
        return "errol.xhtml";
    }
}
